class ArticlesController < ApplicationController
    def show
        @article_current="current"
        @article = Article.find_by_permalink(params[:id])
    end
    
    def index
        @archives_current="current"
        session[:request_uri] = request.request_uri
        @articles = Article.all( :select => 'id, title, preview, permalink, created_at')
    end
    
    def new
        @article = Article.new
        respond_to do |format|
            format.html
            format.xml { render :xml => @article }
        end
    end
    
    def create
        @article = Article.new(params[:article])
        respond_to do |format|
            if @article && @article.save
                flash[:notice] = 'Article published'
                format.html { redirect_to :home}
                format.xml { render :xml => @article, :status => :created, :location => @article }
            else
                format.html { render :action => "new"}
                format.xml { render :xml => @article.errors, :status => :unprocessable_entity }
            end
        end
    end
    
    def edit
        @article = Article.find(params[:id])
        respond_to do |format|
            format.html
            format.xml { render :xml => @article }
        end
    end
    
    def update
        @article = Article.find(params[:id])
        
        respond_to do |format|
            if @article.update_attributes(params[:article])
                flash[:notice]="Article was successfully updated"
                format.html { redirect_to(@article) }
                format.xml { head :ok}
            else
                format.html { render :action => "edit" }
                format.xml { render :xml => @article.errors, :status => :unprocessable_entity}
            end
        end
    end
end